home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / var / lib / dpkg / info / x11-common.postrm < prev    next >
Encoding:
Text File  |  2011-12-16  |  22.9 KB  |  701 lines

  1. #!/bin/sh
  2. # Debian x11-common package post-removal script
  3. # Copyright 1998--2001, 2003 Branden Robinson.
  4. # Licensed under the GNU General Public License, version 2.  See the file
  5. # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
  6. # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
  7.  
  8.  
  9. set -e
  10.  
  11. THIS_PACKAGE=x11-common
  12. THIS_SCRIPT=postrm
  13. CONFIG_DIR=/etc/X11
  14. XWRAPPER_CONFIG="$CONFIG_DIR/Xwrapper.config"
  15. CONFIG_AUX_DIR=/var/lib/x11
  16. XWRAPPER_CONFIG_CHECKSUM="$CONFIG_AUX_DIR/${XWRAPPER_CONFIG##*/}.md5sum"
  17. XWRAPPER_CONFIG_ROSTER="$CONFIG_AUX_DIR/${XWRAPPER_CONFIG##*/}.roster"
  18.  
  19. # This is the X Strike Force shell library for X Window System package
  20. # maintainer scripts.  It serves to define shell functions commonly used by
  21. # such packages, and performs some error checking necessary for proper operation
  22. # of those functions.  By itself, it does not "do" much; the maintainer scripts
  23. # invoke the functions defined here to accomplish package installation and
  24. # removal tasks.
  25.  
  26. # If you are reading this within a Debian package maintainer script (e.g.,
  27. # /var/lib/dpkg/info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
  28. # skip past this library by scanning forward in this file to the string
  29. # "GOBSTOPPER".
  30.  
  31. SOURCE_VERSION=1:7.5+8+squeeze1
  32. OFFICIAL_BUILD=
  33.  
  34. # Use special abnormal exit codes so that problems with this library are more
  35. # easily tracked down.
  36. SHELL_LIB_INTERNAL_ERROR=86
  37. SHELL_LIB_THROWN_ERROR=74
  38. SHELL_LIB_USAGE_ERROR=99
  39.  
  40. # old -> new variable names
  41. if [ -z "$DEBUG_XORG_PACKAGE" ] && [ -n "$DEBUG_XFREE86_PACKAGE" ]; then
  42.   DEBUG_XORG_PACKAGE="$DEBUG_XFREE86_PACKAGE"
  43. fi
  44. if [ -z "$DEBUG_XORG_DEBCONF" ] && [ -n "$DEBUG_XFREE86_DEBCONF" ]; then
  45.   DEBUG_XORG_DEBCONF="$DEBUG_XFREE86_DEBCONF"
  46. fi
  47.  
  48. # initial sanity checks
  49. if [ -z "$THIS_PACKAGE" ]; then
  50.   cat >&2 <<EOF
  51. Error: package maintainer script attempted to use shell library without
  52. definining \$THIS_PACKAGE shell variable.  Please report the package name,
  53. version, and the text of this error message to the Debian Bug Tracking System.
  54. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  55. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  56. "doc-debian" package, or install the "reportbug" package and use the command of
  57. the same name to file a report against version $SOURCE_VERSION of this package.
  58. EOF
  59.   exit $SHELL_LIB_USAGE_ERROR
  60. fi
  61.  
  62. if [ -z "$THIS_SCRIPT" ]; then
  63.   cat >&2 <<EOF
  64. Error: package maintainer script attempted to use shell library without
  65. definining \$THIS_SCRIPT shell variable.  Please report the package name,
  66. version, and the text of this error message to the Debian Bug Tracking System.
  67. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  68. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  69. "doc-debian" package, or install the "reportbug" package and use the command of
  70. the same name to file a report against version $SOURCE_VERSION of the
  71. "$THIS_PACKAGE" package.
  72. EOF
  73.   exit $SHELL_LIB_USAGE_ERROR
  74. fi
  75.  
  76. if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
  77.   RECONFIGURE="true"
  78. else
  79.   RECONFIGURE=
  80. fi
  81.  
  82. if ([ "$1" = "install" ] || [ "$1" = "configure" ]) && [ -z "$2" ]; then
  83.   FIRSTINST="yes"
  84. fi
  85.  
  86. if [ -z "$RECONFIGURE" ] && [ -z "$FIRSTINST" ]; then
  87.   UPGRADE="yes"
  88. fi
  89.  
  90. trap "message;\
  91.       message \"Received signal.  Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
  92.       message;\
  93.       exit 1" HUP INT QUIT TERM
  94.  
  95. reject_nondigits () {
  96.   # syntax: reject_nondigits [ operand ... ]
  97.   #
  98.   # scan operands (typically shell variables whose values cannot be trusted) for
  99.   # characters other than decimal digits and barf if any are found
  100.   while [ -n "$1" ]; do
  101.     # does the operand contain anything but digits?
  102.     if ! expr "$1" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  103.       # can't use die(), because it wraps message() which wraps this function
  104.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_nondigits() encountered" \
  105.            "possibly malicious garbage \"$1\"" >&2
  106.       exit $SHELL_LIB_THROWN_ERROR
  107.     fi
  108.     shift
  109.   done
  110. }
  111.  
  112. reject_unlikely_path_chars () {
  113.   # syntax: reject_unlikely_path_chars [ operand ... ]
  114.   #
  115.   # scan operands (typically shell variables whose values cannot be trusted) for
  116.   # characters unlikely to be seen in a path and which the shell might
  117.   # interpret and barf if any are found
  118.   while [ -n "$1" ]; do
  119.     # does the operand contain any funny characters?
  120.     if expr "$1" : '.*[!$&()*;<>?|].*' > /dev/null 2>&1; then
  121.       # can't use die(), because I want to avoid forward references
  122.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_unlikely_path_chars()" \
  123.            "encountered possibly malicious garbage \"$1\"" >&2
  124.       exit $SHELL_LIB_THROWN_ERROR
  125.     fi
  126.     shift
  127.   done
  128. }
  129.  
  130. # Query the terminal to establish a default number of columns to use for
  131. # displaying messages to the user.  This is used only as a fallback in the
  132. # event the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while
  133. # the script is running, and this cannot, only being calculated once.)
  134. DEFCOLUMNS=$(stty size 2> /dev/null | awk '{print $2}') || true
  135. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  136.   DEFCOLUMNS=80
  137. fi
  138.  
  139. message () {
  140.   # pretty-print messages of arbitrary length
  141.   reject_nondigits "$COLUMNS"
  142.   echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} >&2
  143. }
  144.  
  145. observe () {
  146.   # syntax: observe message ...
  147.   #
  148.   # issue observational message suitable for logging someday when support for
  149.   # it exists in dpkg
  150.   if [ -n "$DEBUG_XORG_PACKAGE" ]; then
  151.     message "$THIS_PACKAGE $THIS_SCRIPT note: $*"
  152.   fi
  153. }
  154.  
  155. warn () {
  156.   # syntax: warn message ...
  157.   #
  158.   # issue warning message suitable for logging someday when support for
  159.   # it exists in dpkg; also send to standard error
  160.   message "$THIS_PACKAGE $THIS_SCRIPT warning: $*"
  161. }
  162.  
  163. die () {
  164.   # syntax: die message ...
  165.   #
  166.   # exit script with error message
  167.   message "$THIS_PACKAGE $THIS_SCRIPT error: $*"
  168.   exit $SHELL_LIB_THROWN_ERROR
  169. }
  170.  
  171. internal_error () {
  172.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  173.   message "internal error: $*"
  174.   if [ -n "$OFFICIAL_BUILD" ]; then
  175.     message "Please report a bug in the $THIS_SCRIPT script of the" \
  176.             "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  177.             "Tracking System.  Include all messages above that mention the" \
  178.             "$THIS_PACKAGE package.  Visit " \
  179.             "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  180.             "instructions, read the file" \
  181.             "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  182.             "package, or install the reportbug package and use the command of" \
  183.             "the same name to file a report."
  184.   fi
  185.   exit $SHELL_LIB_INTERNAL_ERROR
  186. }
  187.  
  188. usage_error () {
  189.   message "usage error: $*"
  190.   message "Please report a bug in the $THIS_SCRIPT script of the" \
  191.           "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  192.           "Tracking System.  Include all messages above that mention the" \
  193.           "$THIS_PACKAGE package.  Visit " \
  194.           "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  195.           "instructions, read the file" \
  196.           "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  197.           "package, or install the reportbug package and use the command of" \
  198.           "the same name to file a report."
  199.   exit $SHELL_LIB_USAGE_ERROR
  200. }
  201.  
  202. font_update () {
  203.   # run $UPDATECMDS in $FONTDIRS
  204.  
  205.   local dir cmd shortcmd x_font_dir_prefix
  206.  
  207.   x_font_dir_prefix="/usr/share/fonts/X11"
  208.  
  209.   if [ -z "$UPDATECMDS" ]; then
  210.     usage_error "font_update() called but \$UPDATECMDS not set"
  211.   fi
  212.   if [ -z "$FONTDIRS" ]; then
  213.     usage_error "font_update() called but \$FONTDIRS not set"
  214.   fi
  215.  
  216.   reject_unlikely_path_chars "$UPDATECMDS"
  217.   reject_unlikely_path_chars "$FONTDIRS"
  218.  
  219.   for dir in $FONTDIRS; do
  220.     if [ -d "$x_font_dir_prefix/$dir" ]; then
  221.       for cmd in $UPDATECMDS; do
  222.         if which "$cmd" > /dev/null 2>&1; then
  223.           shortcmd=${cmd##*/}
  224.           observe "running $shortcmd in $dir font directory"
  225.       cmd_opts=
  226.           if [ "$shortcmd" = "update-fonts-alias" ]; then
  227.             cmd_opts=--x11r7-layout
  228.           fi
  229.           if [ "$shortcmd" = "update-fonts-dir" ]; then
  230.             cmd_opts=--x11r7-layout
  231.           fi
  232.           if [ "$shortcmd" = "update-fonts-scale" ]; then
  233.             cmd_opts=--x11r7-layout
  234.           fi
  235.           $cmd $cmd_opts $dir || warn "$cmd $cmd_opts $dir" \
  236.                               "failed; font directory data may not" \
  237.                               "be up to date"
  238.         else
  239.           warn "$cmd not found; not updating corresponding $dir font" \
  240.                "directory data"
  241.         fi
  242.       done
  243.     else
  244.       warn "$dir is not a directory; not updating font directory data"
  245.     fi
  246.   done
  247. }
  248.  
  249. remove_conffile_prepare () {
  250.   # syntax: remove_conffile_prepare filename official_md5sum ...
  251.   #
  252.   # Check a conffile "filename" against a list of canonical MD5 checksums.
  253.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  254.   # operands provided, then prepare the conffile for removal from the system.
  255.   # We defer actual deletion until the package is configured so that we can
  256.   # roll this operation back if package installation fails.
  257.   #
  258.   # Call this function from a preinst script in the event $1 is "upgrade" or
  259.   # "install" and verify $2 to ensure the package is being upgraded from a
  260.   # version (or installed over a version removed-but-not-purged) prior to the
  261.   # one in which the conffile was obsoleted.
  262.  
  263.   local conffile current_checksum
  264.  
  265.   # validate arguments
  266.   if [ $# -lt 2 ]; then
  267.     usage_error "remove_conffile_prepare() called with wrong number of" \
  268.                 "arguments; expected at least 2, got $#"
  269.     exit $SHELL_LIB_USAGE_ERROR
  270.   fi
  271.  
  272.   conffile="$1"
  273.   shift
  274.  
  275.   # does the conffile even exist?
  276.   if [ -e "$conffile" ]; then
  277.     # calculate its checksum
  278.     current_checksum=$(md5sum < "$conffile" | sed 's/[[:space:]].*//')
  279.     # compare it to each supplied checksum
  280.     while [ -n "$1" ]; do
  281.       if [ "$current_checksum" = "$1" ]; then
  282.         # we found a match; move the confffile and stop looking
  283.         observe "preparing obsolete conffile $conffile for removal"
  284.         mv "$conffile" "$conffile.$THIS_PACKAGE-tmp"
  285.         break
  286.       fi
  287.       shift
  288.     done
  289.   fi
  290. }
  291.  
  292. remove_conffile_lookup () {
  293.   # syntax: remove_conffile_lookup package filename
  294.   #
  295.   # Lookup the md5sum of a conffile in dpkg's database, and prepare for removal
  296.   # if it matches the actual file's md5sum.
  297.   #
  298.   # Call this function when you would call remove_conffile_prepare but only
  299.   # want to check against dpkg's status database instead of known checksums.
  300.  
  301.   local package conffile old_md5sum
  302.  
  303.   # validate arguments
  304.   if [ $# -ne 2 ]; then
  305.     usage_error "remove_conffile_lookup() called with wrong number of" \
  306.                 "arguments; expected 1, got $#"
  307.     exit $SHELL_LIB_USAGE_ERROR
  308.   fi
  309.  
  310.   package="$1"
  311.   conffile="$2"
  312.  
  313.   if ! [ -e "$conffile" ]; then
  314.     return
  315.   fi
  316.   old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$package" | \
  317.     awk '{ if (match($0, "^ '"$conffile"' ")) print $2}')"
  318.   if [ -n "$old_md5sum" ]; then
  319.     remove_conffile_prepare "$conffile" "$old_md5sum"
  320.   fi
  321. }
  322.  
  323. remove_conffile_commit () {
  324.   # syntax: remove_conffile_commit filename
  325.   #
  326.   # Complete the removal of a conffile "filename" that has become obsolete.
  327.   #
  328.   # Call this function from a postinst script after having used
  329.   # remove_conffile_prepare() in the preinst.
  330.  
  331.   local conffile
  332.  
  333.   # validate arguments
  334.   if [ $# -ne 1 ]; then
  335.     usage_error "remove_conffile_commit() called with wrong number of" \
  336.                 "arguments; expected 1, got $#"
  337.     exit $SHELL_LIB_USAGE_ERROR
  338.   fi
  339.  
  340.   conffile="$1"
  341.  
  342.   # if the temporary file created by remove_conffile_prepare() exists, remove it
  343.   if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
  344.     observe "committing removal of obsolete conffile $conffile"
  345.     rm "$conffile.$THIS_PACKAGE-tmp"
  346.   fi
  347. }
  348.  
  349. remove_conffile_rollback () {
  350.   # syntax: remove_conffile_rollback filename
  351.   #
  352.   # Roll back the removal of a conffile "filename".
  353.   #
  354.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  355.   # or "abort-install" is  after having used remove_conffile_prepare() in the
  356.   # preinst.
  357.  
  358.   local conffile
  359.  
  360.   # validate arguments
  361.   if [ $# -ne 1 ]; then
  362.     usage_error "remove_conffile_rollback() called with wrong number of" \
  363.                 "arguments; expected 1, got $#"
  364.     exit $SHELL_LIB_USAGE_ERROR
  365.   fi
  366.  
  367.   conffile="$1"
  368.  
  369.   # if the temporary file created by remove_conffile_prepare() exists, move it
  370.   # back
  371.   if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
  372.     observe "rolling back removal of obsolete conffile $conffile"
  373.     mv "$conffile.$THIS_PACKAGE-tmp" "$conffile"
  374.   fi
  375. }
  376.  
  377. replace_conffile_with_symlink_prepare () {
  378.   # syntax: replace_conffile_with_symlink_prepare oldfilename newfilename \
  379.   # official_md5sum ...
  380.   #
  381.   # Check a conffile "oldfilename" against a list of canonical MD5 checksums.
  382.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  383.   # operands provided, then prepare the conffile for removal from the system.
  384.   # We defer actual deletion until the package is configured so that we can
  385.   # roll this operation back if package installation fails. Otherwise copy it
  386.   # to newfilename and let dpkg handle it through conffiles mechanism.
  387.   #
  388.   # Call this function from a preinst script in the event $1 is "upgrade" or
  389.   # "install" and verify $2 to ensure the package is being upgraded from a
  390.   # version (or installed over a version removed-but-not-purged) prior to the
  391.   # one in which the conffile was obsoleted.
  392.  
  393.   local conffile current_checksum
  394.  
  395.   # validate arguments
  396.   if [ $# -lt 3 ]; then
  397.     usage_error "replace_conffile_with_symlink_prepare() called with wrong" \
  398.                 " number of arguments; expected at least 3, got $#"
  399.     exit $SHELL_LIB_USAGE_ERROR
  400.   fi
  401.  
  402.   oldconffile="$1"
  403.   shift
  404.   newconffile="$1"
  405.   shift
  406.  
  407.   remove_conffile_prepare "$_oldconffile" "$@"
  408.   # If $oldconffile still exists, then md5sums didn't match.
  409.   # Copy it to new one.
  410.   if [ -f "$oldconffile" ]; then
  411.     cp "$oldconffile" "$newconffile"
  412.   fi
  413.  
  414. }
  415.  
  416. replace_conffile_with_symlink_commit () {
  417.   # syntax: replace_conffile_with_symlink_commit oldfilename
  418.   #
  419.   # Complete the removal of a conffile "oldfilename" that has been
  420.   # replaced by a symlink.
  421.   #
  422.   # Call this function from a postinst script after having used
  423.   # replace_conffile_with_symlink_prepare() in the preinst.
  424.  
  425.   local conffile
  426.  
  427.   # validate arguments
  428.   if [ $# -ne 1 ]; then
  429.     usage_error "replace_conffile_with_symlink_commit() called with wrong" \
  430.                 "number of arguments; expected 1, got $#"
  431.     exit $SHELL_LIB_USAGE_ERROR
  432.   fi
  433.  
  434.   conffile="$1"
  435.  
  436.   remove_conffile_commit "$conffile"
  437. }
  438.  
  439. replace_conffile_with_symlink_rollback () {
  440.   # syntax: replace_conffile_with_symlink_rollback oldfilename newfilename
  441.   #
  442.   # Roll back the replacing of a conffile "oldfilename" with symlink to
  443.   # "newfilename".
  444.   #
  445.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  446.   # or "abort-install" and verify $2 to ensure the package failed to upgrade
  447.   # from a version (or install over a version removed-but-not-purged) prior
  448.   # to the one in which the conffile was obsoleted.
  449.   # You should have  used replace_conffile_with_symlink_prepare() in the
  450.   # preinst.
  451.  
  452.   local conffile
  453.  
  454.   # validate arguments
  455.   if [ $# -ne 2 ]; then
  456.     usage_error "replace_conffile_with_symlink_rollback() called with wrong" \
  457.                 "number of arguments; expected 2, got $#"
  458.     exit $SHELL_LIB_USAGE_ERROR
  459.   fi
  460.  
  461.   oldconffile="$1"
  462.   newconffile="$2"
  463.  
  464.   remove_conffile_rollback "$_oldconffile"
  465.   if [ -f "$newconffile" ]; then
  466.     rm "$newconffile"
  467.   fi
  468. }
  469.  
  470. run () {
  471.   # syntax: run command [ argument ... ]
  472.   #
  473.   # Run specified command with optional arguments and report its exit status.
  474.   # Useful for commands whose exit status may be nonzero, but still acceptable,
  475.   # or commands whose failure is not fatal to us.
  476.   #
  477.   # NOTE: Do *not* use this function with db_get or db_metaget commands; in
  478.   # those cases the return value of the debconf command *must* be checked
  479.   # before the string returned by debconf is used for anything.
  480.  
  481.   local retval
  482.  
  483.   # validate arguments
  484.   if [ $# -lt 1 ]; then
  485.     usage_error "run() called with wrong number of arguments; expected at" \
  486.                 "least 1, got $#"
  487.     exit $SHELL_LIB_USAGE_ERROR
  488.   fi
  489.  
  490.   "$@" || retval=$?
  491.  
  492.   if [ ${retval:-0} -ne 0 ]; then
  493.     observe "command \"$*\" exited with status $retval"
  494.   fi
  495. }
  496.  
  497. make_symlink_sane () {
  498.   # syntax: make_symlink_sane symlink target
  499.   #
  500.   # Ensure that the symbolic link symlink exists, and points to target.
  501.   #
  502.   # If symlink does not exist, create it and point it at target.
  503.   #
  504.   # If symlink exists but is not a symbolic link, back it up.
  505.   #
  506.   # If symlink exists, is a symbolic link, but points to the wrong location, fix
  507.   # it.
  508.   #
  509.   # If symlink exists, is a symbolic link, and already points to target, do
  510.   # nothing.
  511.   #
  512.   # This function wouldn't be needed if ln had an -I, --idempotent option.
  513.  
  514.   # Validate arguments.
  515.   if [ $# -ne 2 ]; then
  516.     usage_error "make_symlink_sane() called with wrong number of arguments;" \
  517.       "expected 2, got $#"
  518.     exit $SHELL_LIB_USAGE_ERROR
  519.   fi
  520.  
  521.   # We could just use the positional parameters as-is, but that makes things
  522.   # harder to follow.
  523.   local symlink target
  524.  
  525.   symlink="$1"
  526.   target="$2"
  527.  
  528.   if [ -L "$symlink" ] && [ "$(readlink "$symlink")" = "$target" ]; then
  529.       observe "link from $symlink to $target already exists"
  530.   else
  531.     observe "creating symbolic link from $symlink to $target"
  532.     mkdir -p "${target%/*}" "${symlink%/*}"
  533.     ln -s -b -S ".dpkg-old" "$target" "$symlink"
  534.   fi
  535. }
  536.  
  537. migrate_dir_to_symlink () {
  538.   # syntax: migrate_dir_to_symlink old_location new_location
  539.   #
  540.   # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
  541.   # symbolic link to a directory or vice versa; instead, the existing state
  542.   # (symlink or not) will be left alone and dpkg will follow the symlink if
  543.   # there is one."
  544.   #
  545.   # We have to do it ourselves.
  546.   #
  547.   # This function moves the contents of old_location, a directory, into
  548.   # new_location, a directory, then makes old_location a symbolic link to
  549.   # new_location.
  550.   #
  551.   # old_location need not exist, but if it does, it must be a directory (or a
  552.   # symlink to a directory).  If it is not, it is backed up.  If new_location
  553.   # exists already and is not a directory, it is backed up.
  554.   #
  555.   # This function should be called from a package's preinst so that other
  556.   # packages unpacked after this one --- but before this package's postinst runs
  557.   # --- are unpacked into new_location even if their payloads contain
  558.   # old_location filespecs.
  559.  
  560.   # Validate arguments.
  561.   if [ $# -ne 2 ]; then
  562.     usage_error "migrate_dir_to_symlink() called with wrong number of"
  563.                 "arguments; expected 2, got $#"
  564.     exit $SHELL_LIB_USAGE_ERROR
  565.   fi
  566.  
  567.   # We could just use the positional parameters as-is, but that makes things
  568.   # harder to follow.
  569.   local new old
  570.  
  571.   old="$1"
  572.   new="$2"
  573.  
  574.   # Is old location a symlink?
  575.   if [ -L "$old" ]; then
  576.     # Does it already point to new location?
  577.     if [ "$(readlink "$old")" = "$new" ]; then
  578.       # Nothing to do; migration has already been done.
  579.       observe "migration of $old to $new already done"
  580.       return 0
  581.     else
  582.       # Back it up.
  583.       warn "backing up symbolic link $old as $old.dpkg-old"
  584.       mv -b "$old" "$old.dpkg-old"
  585.     fi
  586.   fi
  587.  
  588.   # Does old location exist, but is not a directory?
  589.   if [ -e "$old" ] && ! [ -d "$old" ]; then
  590.       # Back it up.
  591.       warn "backing up non-directory $old as $old.dpkg-old"
  592.       mv -b "$old" "$old.dpkg-old"
  593.   fi
  594.  
  595.   observe "migrating $old to $new"
  596.  
  597.   # Is new location a symlink?
  598.   if [ -L "$new" ]; then
  599.     # Does it point the wrong way, i.e., back to where we're migrating from?
  600.     if [ "$(readlink "$new")" = "$old" ]; then
  601.       # Get rid of it.
  602.       observe "removing symbolic link $new which points to $old"
  603.       rm "$new"
  604.     else
  605.       # Back it up.
  606.       warn "backing up symbolic link $new as $new.dpkg-old"
  607.       mv -b "$new" "$new.dpkg-old"
  608.     fi
  609.   fi
  610.  
  611.   # Does new location exist, but is not a directory?
  612.   if [ -e "$new" ] && ! [ -d "$new" ]; then
  613.     warn "backing up non-directory $new as $new.dpkg-old"
  614.     mv -b "$new" "$new.dpkg-old"
  615.   fi
  616.  
  617.   # Create new directory if it does not yet exist.
  618.   if ! [ -e "$new" ]; then
  619.     observe "creating $new"
  620.     mkdir -p "$new"
  621.   fi
  622.  
  623.   # Copy files in old location to new location.  Back up any filenames that
  624.   # already exist in the new location with the extension ".dpkg-old".
  625.   observe "copying files from $old to $new"
  626.   if ! (cd "$old" && cp -a -b -S ".dpkg-old" . "$new"); then
  627.     die "error(s) encountered while copying files from $old to $new"
  628.   fi
  629.  
  630.   # Remove files at old location.
  631.   observe "removing $old"
  632.   rm -r "$old"
  633.  
  634.   # Create symlink from old location to new location.
  635.   make_symlink_sane "$old" "$new"
  636. }
  637.  
  638. # vim:set ai et sw=2 ts=2 tw=80:
  639.  
  640. # GOBSTOPPER: The X Strike Force shell library ends here.
  641.  
  642. # clean up non-conffile configuration files and related materials on purge
  643. if [ "$1" = "purge" ]; then
  644.   # de-register this package as a handler of the X server wrapper config file
  645.   if [ -e "$XWRAPPER_CONFIG_ROSTER" ]; then
  646.     # check existing roster file for our package name
  647.     if fgrep -qx "$THIS_PACKAGE" "$XWRAPPER_CONFIG_ROSTER" 2>/dev/null; then
  648.       # construct temporary roster file with our package name removed, ignoring
  649.       # failure
  650.       fgrep -vx "$THIS_PACKAGE" "$XWRAPPER_CONFIG_ROSTER" > \
  651.         "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp" 2>/dev/null || true
  652.       # is there anything left?
  653.       if [ -s "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp" ]; then
  654.         # yes, replace the roster file
  655.         mv "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp" "$XWRAPPER_CONFIG_ROSTER"
  656.       else
  657.         # no; remove both the roster and our temporary copy
  658.         rm -f "$XWRAPPER_CONFIG_ROSTER" "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp"
  659.         # remove X server wrapper config file if it was still managed by the
  660.         # package
  661.         if [ -e "$XWRAPPER_CONFIG_CHECKSUM" ]; then
  662.           # does it exist?
  663.           if [ -e "$XWRAPPER_CONFIG" ]; then
  664.             # does the current MD5 checksum match the stored checksum?
  665.             if [ "$(md5sum "$XWRAPPER_CONFIG")" \
  666.                  = "$(cat "$XWRAPPER_CONFIG_CHECKSUM")" ]; then
  667.               # yes; remove the config file
  668.               rm -f "$XWRAPPER_CONFIG"
  669.             fi
  670.           fi
  671.           # remove the checksum file; any remaining X server wrapper config file
  672.           # still on the system at this point is no longer being managed (local
  673.           # user customization)
  674.           rm -f "$XWRAPPER_CONFIG_CHECKSUM"
  675.         fi
  676.       fi
  677.     fi
  678.   fi
  679.  
  680.   for DIR in "$CONFIG_DIR" "$CONFIG_AUX_DIR"; do
  681.       rmdir "$DIR" 2> /dev/null || true
  682.   done
  683. fi
  684.  
  685. # Automatically added by dh_installinit
  686. if [ "$1" = "purge" ] ; then
  687.     update-rc.d x11-common remove >/dev/null
  688. fi
  689. # End automatically added section
  690. # Automatically added by dh_installdebconf
  691. if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then
  692.     . /usr/share/debconf/confmodule
  693.     db_purge
  694. fi
  695. # End automatically added section
  696.  
  697.  
  698. exit 0
  699.  
  700. # vim:set ai et sts=2 sw=2 tw=80:
  701.